#include <interfacelib/window/ScrollBar.h>

using namespace interfacelib::Window;

ScrollBar::ScrollBar() : m_scrollButton( NULL )
{
}

ScrollBar::~ScrollBar()
{
}

bool ScrollBar::addScrollBar( const char *imageName )
{
	if ( m_scrollButton )
	{
		remove( m_scrollButton );
	}
	{
		m_scrollButton = new ScrollButton;			
		m_scrollButton->create( imageName, 0, 0 );
		add( m_scrollButton );
	}
	return ( true );
}

const int ScrollBar::getPosPercent() 
{
	POINT pt;
	m_scrollButton->getWindowPos( &pt, false );
	return (int)( pt.y * 100.f / getHeight() );
}

void ScrollBar::setPosPercent( const int PosPercent )
{
	int yPos = ( int )( PosPercent * getHeight() / 100.f );
	m_scrollButton->setWindowPos( 0, yPos );
}

void ScrollBar::ScrollButton::onMouseMove( int flags, POINT pt )
{
	if ( getState() == BUTTON_STATE_CLICK )
	{
		pt.x = 0;
		Button::onMouseMove( flags, pt );
		postMessage( WM_SCROLL_NOTIFY, ( LPARAM )&pt, ( WPARAM )this );
	}	
}